package com.itheima.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
public class MyAdvice {
    @Pointcut("execution(* com.itheima.dao.BookDao.findName(..))")
    private void pt() {
    }

    //    @Before("pt()")
    public void before(JoinPoint pj) {
        Object[] args = pj.getArgs();
        System.out.println(Arrays.toString(args));
        System.out.println("before Advice....");
    }

    //    @After("pt()")
    public void after(JoinPoint pj) {
        Object[] args = pj.getArgs();
        System.out.println(Arrays.toString(args));
        System.out.println("after Advice....");
    }

    //    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        Object[] args = pjp.getArgs();
        args[0] = 66;
        Object proceed = pjp.proceed(args);
        return proceed;
    }

    @AfterReturning(value = "pt()", returning = "ret")
    public void afterReturning(JoinPoint pjp, Object ret) {
        System.out.println("afterReturning advice...");
    }

    //    @AfterThrowing("pt()")
    public void afterThrowing() {
        System.out.println("afterThrowing advice ...");
    }
}

